package com.mall.web.controller.course.admin;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.mall.course.courseSignup.domain.dto.CourseSignupDto;
import com.mall.course.courseSignup.domain.vo.CourseSignupVo;
import com.mall.course.courseSignup.service.ICourseSignupService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.mall.common.annotation.Log;
import com.mall.common.core.controller.BaseController;
import com.mall.common.core.domain.AjaxResult;
import com.mall.common.enums.BusinessType;
import com.mall.common.utils.poi.ExcelUtil;
import com.mall.common.core.page.TableDataInfo;

/**
 * 课程报名Controller
 * 
 * @author mall
 * @date 2024-05-17
 */
@RestController
@RequestMapping("/admin/course/courseSignup")
public class CourseSignupController extends BaseController
{
    @Autowired
    private ICourseSignupService courseSignupService;

    /**
     * 查询课程报名列表
     */
    @PreAuthorize("@ss.hasPermi('course:courseSignup:list')")
    @GetMapping("/list")
    public TableDataInfo list(CourseSignupDto courseSignupDto)
    {
        startPage();
        List<CourseSignupVo> list = courseSignupService.selectCourseSignupList(courseSignupDto);
        return getDataTable(list);
    }

    /**
     * 导出课程报名列表
     */
    @PreAuthorize("@ss.hasPermi('course:courseSignup:export')")
    @Log(title = "课程报名", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CourseSignupDto courseSignupDto)
    {
        List<CourseSignupVo> list = courseSignupService.selectCourseSignupList(courseSignupDto);
        ExcelUtil<CourseSignupVo> util = new ExcelUtil<CourseSignupVo>(CourseSignupVo.class);
        util.exportExcel(response, list, "课程报名数据");
    }

    /**
     * 获取课程报名详细信息
     */
    @PreAuthorize("@ss.hasPermi('course:courseSignup:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(courseSignupService.selectCourseSignupById(id));
    }

    /**
     * 新增课程报名
     */
    @PreAuthorize("@ss.hasPermi('course:courseSignup:add')")
    @Log(title = "课程报名", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CourseSignupDto courseSignupDto)
    {
        return toAjax(courseSignupService.insertCourseSignup(courseSignupDto));
    }

    /**
     * 修改课程报名
     */
    @PreAuthorize("@ss.hasPermi('course:courseSignup:edit')")
    @Log(title = "课程报名", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CourseSignupDto courseSignupDto)
    {
        return toAjax(courseSignupService.updateCourseSignup(courseSignupDto));
    }

    /**
     * 删除课程报名
     */
    @PreAuthorize("@ss.hasPermi('course:courseSignup:remove')")
    @Log(title = "课程报名", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(courseSignupService.deleteCourseSignupByIds(ids));
    }
}
